<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'tce.label', default: 'Tce')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="body">
            <div class="cabelistlateral"><img src="${resource(dir:'images',file:'seta_cabecalho_20x20.png')}" /> TCEs</div><br/>
            <g:if test="${flash.message}">
                <div class="message">${flash.message}</div>
            </g:if>
            <div class="list">
                <table>
                    <thead>
                        <tr>
                            <g:sortableColumn property="dtInicio" title="${message(code: 'tce.dtInicio.label', default: 'Data Início')}" />
                            <g:sortableColumn property="dtFim" title="${message(code: 'tce.dtFim.label', default: 'Data Fim')}" />
                            <g:sortableColumn property="supCpf" title="${message(code: 'tce.supNome.label', default: 'Supervisor')}" />
                            <td>Instituição Ensino</td>
                            <td>Situação</td>
                            <td>Sequência</td>
                            <td colspan="2">Ações</td>
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${tceInstanceList}" status="i" var="tceInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                            <%
                            String situacao;
                            String style;
                            if(tceInstance?.situacao == '0'){
                                situacao = "Aguardando";
                                style    = " style='color:#ff0000; font-weight:bold;'";
                            }else if(tceInstance?.situacao == '1' && tceInstance.dtFim.after(new Date())){
                                situacao = "Gerado";
                                style    = " style='color:#006600; font-weight:bold;'";
                            }else if(tceInstance?.dtRescisao){
                                situacao = "Recindido";
                                style    = " style='color:#f78b00; font-weight:bold;'";
                            }
                            if(!tceInstance.dtFim.after(new Date()) && (tceInstance?.situacao != '0')){
                                situacao = "Concluído";
                                style    = " style='color:#000000; font-weight:bold;'";
                            }
                            %>
                            <td><g:formatDate format="dd-MM-yyyy" date="${tceInstance.dtInicio}" /></td>
                            <td><g:formatDate format="dd-MM-yyyy" date="${tceInstance.dtFim}" /></td>
                            <td>${fieldValue(bean: tceInstance, field: "supNome")}</td>
                            <td>${tceInstance?.instituicaoEnsino?.nome}</td>
                            <td<%=style%>>${situacao}</td>
                            <td>${fieldValue(bean: tceInstance, field: "sequencia")}</td>
                            <td class="ico">
                                <a href="${createLink(controller:'tce', action:'edit', id:tceInstance.id)}">
                                    <img src="${resource(dir:'images',file:'ico_edit.png')}" alt="Gerar TCE" title="Gerar TCE"/>
                                </a>
                            </td>
                            <td class="ico">
                                <a href="${createLink(controller:'tce', action:'show', id:tceInstance.id)}">
                                    <img src="${resource(dir:'images',file:'ico_preview.png')}" alt="Gerar TCE" title="Gerar TCE"/>
                                </a>
                            </td>
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            <div class="paginateButtons">
                <g:paginate total="${tceInstanceTotal}" />
            </div>
        </div>
    </body>
</html>
